<?php
App::uses('AppModel', 'Model');
/**
 * User Model
 *
 * @property Survey $Survey
 */
class User extends AppModel {
	public $useTable = 'users';

/**
 * Display field
 *
 * @var string
 */
	public $displayField = 'full_name';


	//The Associations below have been created with all possible keys, those that are not needed can be removed

/**
 * hasMany associations
 *
 * @var array
 */
	public $hasMany = array(
		'Survey' => array(
			'className' => 'Survey',
			'foreignKey' => 'user_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		)
	);

	public function beforeSave($options = array()) {
	    if (isset($this->data[$this->alias]['password'])) {
	        $this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
	    }
	    return true;
	}

	public $virtualFields = array(
		'full_name' => "CONCAT(User.first_name, ' ', User.last_name)",
	);

}
